// packageI/lawyerPlatform/detail/detail.js
var app =getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nav_text: ['律师简介', '法律服务'],
    type_name:"",
    text: "",
    lawyer_type:"",
    order_type:"",
    lawyerId:"",
    listServe:[],//律师服务列表
    domain_nickName:[],//领域名称
    lawyerInfo:{},//律师详情
    lawfirmName:"",
    address:"",
    form:{
      avatar_image:"",
      status:1,
      introduction:"",
      thumb_image:"",
      address:"",
    },
    addressName:"",//律所详情地址
    streetId:"",
    areaId:"",
    cityId:"",
    provinceId:"",
    streetName:"",
    listData:[],
    id:"",
    nav_index:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      if(options.type_name == 'lawyer'){
        wx.setNavigationBarTitle({
          title: '律师详情',
        })
      }else{
        wx.setNavigationBarTitle({
          title: '律所详情',
        })
      }
      this.setData({type_name:options.type_name,id:options.id})
      this.getData()
  },
  toggle_title(e){
    this.setData({nav_index:e.currentTarget.dataset.i})
  },
  getData(){
      let path = this.data.type_name == 'lawyer'?"plugin.lawyer-platform.frontend.controllers.lawyer.getDetail":"plugin.lawyer-platform.frontend.controllers.lawyer-firm.getDetail";
      let url = app.getNetAddresss(path);

      let id = this.data.id;
      app._postNetWork({
        url,
        data:{id},
        success:(res)=>{
          if(res.data.result == 1){
            let data = res.data.data.detail;
            this.setData({
                lawyerInfo:data,
                domain_nickName:data.category_data,
            })
            if(this.data.type_name == 'office'){
              let data = res.data.data.detail;
               this.setData({
                areaId :data.address.area,
                cityId :data.address.city,
                provinceId:data.address.province,
                "form.avatar_image" : data.logo_image,
                streetId : data.address.stree,
              })
                wx.getStorage({
                  key:"provinceData",
                  success:res=>{
                    let province = wx.getStorageSync('provinceData'),
                        city = wx.getStorageSync('cityData'),
                        area = wx.getStorageSync('districtData'),
                        provinceName = province.filter(item => item.id == data.address.province),
                        cityName = city.filter(item => item.id == data.address.city),
                        districtName = area.filter(item => item.id == data.address.area),
                        addressName = provinceName[0].areaname + cityName[0].areaname + districtName[0].areaname
                      this.setData({addressName})
                  },
                  fail:res=>{
                    app._getNetWork({
                      url: app.getNetAddresss("member.member-address.address"),
                      success: function (res) {

                        var response = res.data;
                        console.log(response)
                        var province = response.data.province;
                        var city = response.data.city;
                        var district = response.data.district;
                        wx.setStorage({
                          key: 'provinceData',
                          data: province
                        });
                        wx.setStorage({
                          key: 'cityData',
                          data: city
                        });
                        wx.setStorage({
                          key: 'districtData',
                          data: district
                        });

                      },
                      fail: function (res) {},
                    });
                  }
                })
            }else{
              this.setData({
                lawfirmName : data.lawyer_firm.name,
                listServe : data.goods,
                "form.avatar_image" : data.avatar_image
              })
            }
            this.setData({
              "form.status":data.status
            })
          }
        }
      })
  },
  LinkeOffice(){
    wx.navigateTo({
      url: '/packageI/lawyerPlatform/detail/detail?type_name=office&id='+this.data.lawyerInfo.lf_id,
    })
  },
  consult(data){
    let {service_day,goods_id,amount,consult_type} = data.detail;
    let json = {
      service_day,
      goods_id,
      l_id:this.data.lawyerInfo.id,
      price:amount,
      service_type:consult_type==0?1:2,
      l_name:this.data.lawyerInfo.name,
      lf_id:this.data.lawyerInfo.lf_id,
      lf_name:this.data.lawyerInfo.lawyer_firm.name,
      lf_province_name:this.data.lawyerInfo.lawyer_firm.lf_province_name,
      lf_city_name:this.data.lawyerInfo.lawyer_firm.lf_city_name,
      lf_area_name:this.data.lawyerInfo.lawyer_firm.lf_area_name,
      lf_street_name:this.data.lawyerInfo.lawyer_firm.lf_street_name,
      lf_address_detail:this.data.lawyerInfo.lawyer_firm.address_detail
    }
    let url = app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.create");
     app._postNetWork({
       url,
       data:json,
       success:res => {
        if(res.data.result == 1){
          wx.navigateTo({
            url: '/packageD/buy/orderPay/orderPay?order_id='+res.data.data.order_ids
          })
        }else{
          app.tips(res.data.msg)
        }
       }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})